package com.framework.utils.verified;

import com.framework.exception.RRException;
import com.framework.utils.httpClient.HttpUtils;
import com.framework.utils.json.JsonUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * 功能描述: 身份证、姓名校验
 *
 * @author ck
 * @date 2018/9/25 13:20
 */
public class Verified {

	private static final String HOST = "http://aliyun.id98.cn";

	private static final String PATH = "/idcard";

	private static final String METHOD = "GET";

	private static final String APPCODE = "98b7bce93cc54c24998c7b0338cc78f0";

	public static void  verfiedIDCard(String name, String cardNo) {
		Map<String, String> headers = new HashMap<String, String>();
		headers.put("Authorization", "APPCODE " + APPCODE);
		Map<String, String> querys = new HashMap<String, String>();
		querys.put("cardno", cardNo);
		querys.put("name", name);
		String err = "0";
		try {
			HttpResponse response = HttpUtils.doGet(HOST, PATH, METHOD, headers, querys);
			Map<String, Object> map = JsonUtils.fromJson(EntityUtils.toString(response.getEntity()));
			Map<String, Object> map1= JsonUtils.fromJson(map.get("data").toString());
			err = map1.get("err").toString();
		} catch (Exception e) {
			e.printStackTrace();
			e.getMessage();
			throw new RRException("9000","接口调用失败");
		}
		if(StringUtils.equals("-1",err)){
			throw new RRException("9000","身份证校验错误");
		}
	}

	public static void main(String[] args) {
		Verified.verfiedIDCard("汪琪","3408231999403194012");
	}

}
